package br.teste;

import java.awt.Button;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;

public class Page extends JPanel{
	public Component compSelected = null;
	
	public Page() {
		super(null);
		addMouseListener(pageMouse);
		addFocusListener(focusPage);
		Button btn = new Button("Quadrado");
		btn.addActionListener(actionBtn);
		btn.setSize(2000, 50);
		add(btn);
		setBackground(Color.CYAN);
	}
	
	MouseAdapter pageMouse = new MouseAdapter() {
		public void mousePressed(MouseEvent e) {
			if( compSelected != null ){
				add(compSelected);
				compSelected.requestFocus();
				compSelected.setBounds(e.getX(), e.getY(), 300, 300);
				revalidate();
				compSelected = null;
			}
		};
	};
	
	FocusAdapter focusPage = new FocusAdapter() {
		@Override
		public void focusGained(FocusEvent e) {
			super.focusGained(e);
		}
	};
	
	ActionListener actionBtn = new ActionListener(){
		@Override
		public void actionPerformed(ActionEvent arg0) {
			compSelected = new Resizable(0, 0);
		}
	};
	
}
